﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Jäckvik_Grupp4
{
    public partial class BookingConfirmation : Form
    {
        private LOGIC.LogicInvoice bookingConfirmation = new LOGIC.LogicInvoice();
        private int tempInvoiceID;
        private int tempBookingID;

        public BookingConfirmation(LOGIC.LogicInvoice bookingConfirmation, int tempInvoiceID, int tempBookingID)
        {
            InitializeComponent();
            string invoicedetails = bookingConfirmation.GetInvoice(tempBookingID)[1].ToString();
            string[] invoiceSplit = invoicedetails.Split('\t');
            this.bookingConfirmation = bookingConfirmation;
            this.tempInvoiceID = tempInvoiceID;
            this.tempBookingID = tempBookingID;

            double BookingCSum = (double.Parse(invoiceSplit[11]) * 0.15);
            double sumNoVat = (BookingCSum * 0.88);//29
            double Vat = (BookingCSum - sumNoVat);
          
            labelInvoiceID.Text = invoiceSplit[1];
            labelGuestID.Text = invoiceSplit[2];
            labelGuestName.Text = invoiceSplit[3]+" " + invoiceSplit[4];
            labelAdress.Text = invoiceSplit[5];
            labelZipAndCity.Text = invoiceSplit[6] +" "+ invoiceSplit[7];
            labelStaffName.Text = invoiceSplit[8] + " " + invoiceSplit[9];
            labelPrintDate.Text = invoiceSplit[10];
            labelTotalSum.Text = BookingCSum.ToString();
            labelSumExVac.Text = sumNoVat.ToString();
            labelVatSum.Text = Vat.ToString();
            labelReference.Text = invoiceSplit[3] + " " + invoiceSplit[4];
          
                // listBoxInvoice.DataSource = logicInvoice.GetInvoice(tempBookingID);
          listBoxInvoice.DataSource = bookingConfirmation.GetWholeInvoice(tempBookingID);
        }

        private void BookingConfirmation_Load(object sender, EventArgs e)
        {
            SaveAsBitMap(this, "C:\\" + tempBookingID + "B.bmp"); 
        }

        public void SaveAsBitMap(Control control, string fileName)
        {
            Graphics g = control.CreateGraphics();
            Bitmap bmp = new Bitmap(control.Width, control.Height);
            control.DrawToBitmap(bmp, new Rectangle(0, 0, control.Width, control.Height));
            bmp.Save(fileName);
            bmp.Dispose();
            g.Dispose();
        }


        
       
    }
}
